package models

import (
	"github.com/astaxie/beego/orm"
	"shopping/helper"
	"github.com/astaxie/beego"
)

type Itemnum struct{
	Id      int
	Itemid  int
	Num     int
}

func (n *Itemnum) Addmin(itid int, num int)(string){
	o := orm.NewOrm()
	res, errrow := o.Raw("UPDATE Itemnum SET num = ? WHERE Itemid = ?", num, itid).Exec()
	//  res, err := o.Raw("UPDATE user SET name = ?", "your").Exec()
	if errrow == nil {
		num, _ := res.RowsAffected()
		return helper.I64ts(num)+"更新成功"
	}
	return "更新失败"
}


func (n *Itemnum) Additem(itid int,num int) (int64,error) {
	o := orm.NewOrm()
	var itn Itemnum
	itn.Itemid = itid
	itn.Num = num
	beego.Debug("itid",itid)
	id, err := o.Insert(&itn)
	//beego.Debug(err)
	return id, err
}

